﻿using System.Windows;
using System.Windows.Forms;
using Foundation;
using Foundation.ExtensionMethods;
using Poet.ViewModels;
using Application = System.Windows.Application;

namespace Poet.Views
{
    /// <summary>
    /// Interaction logic for Window2.xaml
    /// </summary>
    public partial class TrayView
    {
        public TrayView()
        {
            InitializeComponent();

            DataContextChanged +=
                (o, e) =>
                    {
                        var viewModel = e.NewValue as ViewModel;
                        TrayMenu.DataContext = e.NewValue;
                        if (viewModel != null)
                            TrayMenu.CommandBindings.AddRangeOnlyExclusiveItems(viewModel.CommandBindings);
                    };

            NotifyIcon.BalloonTipText = @"Poet";
            NotifyIcon.MouseClick +=
                (o, e) =>
                    {
                        if (e.Button != MouseButtons.Right)
                            TrunkViewModel.IsShown = !TrunkViewModel.IsShown;
                        else TrayMenu.IsOpen = !TrayMenu.IsOpen;
                    };

            NotifyIcon.MouseMove +=
                (o, e) =>
                    {
                        if (e.Button == MouseButtons.Left && Application.Current.MainWindow.WindowState == WindowState.Minimized)
                            TrunkViewModel.IsShown = true;
                    };
        }

        private TrunkViewModel TrunkViewModel
        {
            get { return DataContext as TrunkViewModel; }
        }

        public new void Show()
        {
        }
    }
}
